<template>
  <el-container class="loginPage">
    <el-main class="loginForm">
      <h3>智慧园区-登录</h3>
      <el-form
        ref="loginForm"
        title="智慧园区-登录"
        :model="verifyForm"
        :rules="rules"
      >
        <el-form-item label="账号" prop="username">
          <el-input v-model="verifyForm.username" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="verifyForm.password" show-password />
        </el-form-item>
        <el-row type="flex" justify="center" align="middle">
          <el-col :span="21">
            <el-button
              style="width: 150px"
              type="primary"
              size="medium"
              @click="getWisdomLogin"
            >登录</el-button>
            <el-button style="width: 150px" size="medium" @click="cancelLogin">取消</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      verifyForm: {
        username: 'demo',
        password: 'zh@hm#23'
      },
      rules: {
        username: [
          { required: true, message: '账号不能为空', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {

    getWisdomLogin() { // 调用登录请求
      this.$refs.loginForm.validate(isOK => {
        if (isOK) { // 账号密码验证成功，调用登录请求
          this.$store.dispatch('user/getWisdomLogin', this.verifyForm)
        }
      })
    },
    cancelLogin() { // 重置表单
      this.$refs.loginForm.resetFields()
    }
  }
}
</script>

<style scoped>
.loginPage {
  background-image: url("../../assets/kb.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
}
.loginForm {
  max-width: 400px;
  width: 100%;
  background-color: rgb(254, 254, 254);
}
</style>
